import {PropType} from 'vue'

/**表单多选 */
const CoustomCheckbox = defineComponent({
  props: {
    value: {
      type: Array as PropType<string[]>,
      default: [],
    },
    name: {
      type: String,
      required: true,
    },
    options: {
      type: Array as PropType<any[]>,
      default: [],
    },
  },
  emits: {
    // checked: (data: string, record: any): boolean => true,
    // unchecked: (data: string, record: any): boolean => true,
    'update:value': (data: string[] | number[]): boolean => true,
  },
  setup(props, {slots, emit}) {
    let model = ref<any[]>([])

    watch(
      () => model.value,
      n => {
        emit('update:value', n)
      }
    )
    onMounted(() => {
      if (props.value && props.value.length) {
        model.value = props.value
      }
    })
    return () => (
      <a-checkbox-group v-model={[model.value, 'value']} name={props.name}>
        {props.options.map(item => (
          <a-checkbox class="m-2" value={item.dictCode} name={props.name}>
            {item.dictName}
          </a-checkbox>
        ))}
      </a-checkbox-group>
    )
  },
})

export default CoustomCheckbox
